package org.tedu.cloudnote.serviceImpl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.tedu.cloudnote.dao.NoteDao;
import org.tedu.cloudnote.entity.Note;
import org.tedu.cloudnote.service.NoteService;
import org.tedu.cloudnote.util.NoteResult;
import org.tedu.cloudnote.util.NoteUtil;

@Service("noteService")
public class NoteServiceImpl implements NoteService{
	@Resource
	private NoteDao dao;
	public NoteResult loadBookNotes(String cnNotebook_id) {
		List<Note> list=dao.findByBookId(cnNotebook_id);
		NoteResult result=new NoteResult();
		result.setStatus(0);
		result.setMsg("加载笔记列表成功");
		result.setData(list);
		return result;
	}
	public NoteResult loadDetail(String cn_note_id) {
		Note note=dao.findloadDetail(cn_note_id);
		NoteResult result=new NoteResult();
		result.setStatus(0);
		result.setMsg("加载笔记内容成功");
		result.setData(note);
		return result;
	}
	public NoteResult updateNote(String cnNoteId, String cnNoteTitle,
			String cnNoteBody) {
		NoteResult result=new NoteResult();
		Note note=new Note();
		note.setCn_note_id(cnNoteId);
		note.setCn_note_title(cnNoteTitle);
		note.setCn_note_body(cnNoteBody);
		note.setCn_note_last_modify_time(System.currentTimeMillis());
		dao.update(note);
		result.setStatus(0);
		result.setMsg("保存成功");
		return result;
	}
	public NoteResult addNote(String userId, String bookId, String noteTitle) {
		NoteResult result=new NoteResult();
		Note note=new Note();
		String noteId=NoteUtil.createId();
		note.setCn_note_id(noteId);
		note.setCn_notebook_id(bookId);
		note.setCn_user_id(userId);
		note.setCn_note_status_id("1");
		note.setCn_note_type_id("1");
		note.setCn_note_title(noteTitle);
		note.setCn_note_body("");
		Long time=System.currentTimeMillis();
		note.setCn_note_create_time(time);
		note.setCn_note_last_modify_time(time);
		dao.add(note);
		result.setStatus(0);
		result.setMsg("创建笔记成功");
		result.setData(note);
		return result;
	}
}
